home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 466_01 / SRC / TOPICLOG.H < prev   
Encoding:
C/C++ Source or Header  |  1996-12-20  |  5.7 KB  |  231 lines

  1. // TOPICLOG.H: Topic tag, object, and list definitions.
  2.  
  3. #define MAXNUMFIELDS   6
  4.  
  5. #define LOGADD_BREAKLINE 0x01
  6.  
  7. int RetrieveFileText(char *szFile, char *&szBuf);
  8.  
  9. //@class Stores the text and other informatoin for
  10. // a tag. Thsi object is stored within a <c CTopic>
  11. // object.
  12.  
  13. class CTag : public CObject 
  14. {
  15. public:
  16.     //@cmember Tag name.
  17.     CString         sTag;
  18.  
  19.     //@cmember Count of tag fields.
  20.     int             nFields;
  21.  
  22.     //@cmember Array of pointers to field text strings.
  23.     // These are cleared from memory when the tag is
  24.     // written to the temp file.
  25.     char            *aszFieldText[MAXNUMFIELDS];
  26.  
  27.     //@cmember Array of field character count values.
  28.     unsigned int    anFieldLen[MAXNUMFIELDS];
  29.  
  30.     //@cmember Line from source fiel on which tag started.
  31.     long            lSrcLineNum;
  32.  
  33.     //@cmember TAGOPTIONS | nState | List of tag options.
  34.     struct TAGOPTIONS {
  35.         unsigned IsExample : 1;
  36.         unsigned WasOutput : 1;
  37.     } nState;
  38.  
  39.     //@cmember Constructors
  40.     CTag(void);
  41.  
  42.     //@cmember Destructor
  43.     ~CTag(void);
  44.  
  45.     //@cmember Frees any tag text memory allocated
  46.     void FreeText(void);
  47. };
  48.  
  49.  
  50. typedef CTypedPtrList<CObList, CTag *> CTagList;
  51.  
  52. //@class Stores information for an Autoduck topic.
  53. // This object is stored within a <c CTopicLog>
  54. // object.
  55.  
  56. class CTopic : public CObject
  57. {
  58. public:
  59.     //@cmember Constructor
  60.     CTopic(void);
  61.  
  62.     //@cmember Destructor
  63.     ~CTopic(void);
  64.  
  65.     //@cmember Writes the topic text to a temporary file.
  66.  
  67.     int  Write(CFile &f);
  68.  
  69.     //@cmember Reads the topic text from a temporary file.
  70.     int  Read(CFile &f);
  71.  
  72.     //@cmember Assigns a linked list of <c CTag> objects
  73.     // to the topic.
  74.  
  75.     void SetTags(CTagList &list);
  76.  
  77.     //@cmember Returns TRUE if the topic has an associated
  78.     // tag list.
  79.  
  80.     BOOL HasTags(void) { return !m_listTags.IsEmpty(); }
  81.  
  82.     //@cmember Returns the CTag structure for the topic, or
  83.     // NULL if this is an empty topic.
  84.  
  85.     CTag *GetTopicTag(void);
  86.  
  87. #ifdef _DEBUG
  88.     //@cmember Dumps the contents of the tag to the output
  89.     
  90.     void Dump( CDumpContext &dc ) const;
  91. #endif
  92.  
  93. public:
  94.     //@cmember Sets the tag name.
  95.     
  96.     void SetName(const char *sz);
  97.  
  98.     //@cmember Sets the context string.
  99.     void SetContext(const char *sz);
  100.  
  101.     //@cmember Sets the offset within the temp file. 
  102.  
  103.     void SetOffset(long l);
  104.  
  105.     //@cmember Sets the sorting weight.
  106.     void SetWeight(int n);
  107.  
  108.     //@cmember Sets the index of the set of doc tags
  109.     // that were active when the tag was parsed.
  110.  
  111.     void SetDocTag(int n) { m_nDocTag = n; }
  112.  
  113.     //@cmember Returns index of doc tag for topic.
  114.     const int GetDocTag(void) { return m_nDocTag; }
  115.  
  116.     //@cmember Returns local doc tag (defined via @tag:(DOC TAG)
  117.     // syntax
  118.  
  119.     const char *GetLocalDocTag(void) { return m_sLocalDocTag; }
  120.  
  121.     //@cmember Sets local doc tag.
  122.  
  123.     void SetLocalDocTag(const char *sz) { m_sLocalDocTag = sz; }
  124.  
  125.     //@cmember Sets the index of the topic sourcefile.
  126.     void SetSrcFn(int n) { m_nSrcFn = n; }
  127.  
  128.     //@cmember Get the source file index.
  129.     int GetSrcFn(void) { return m_nSrcFn; }
  130.  
  131.     //@cmember Gets source line number for topic.
  132.     long GetSrcLine(void) { return m_lSrcLineNum; }
  133.  
  134.     //@cmember Sets source line number for topic.
  135.     void SetSrcLine(long l) { m_lSrcLineNum = l; }
  136.  
  137. public:
  138.     //@cmember Gets null-terminated string for context
  139.     // name.
  140.     const char *GetContext(void);
  141.  
  142.     //@cmember Gets null-terminated topic name.
  143.     const char *GetName(void);
  144.  
  145.     //@cmember Gets the head of the <c CTag> list for the topic.
  146.     CTagList &GetTags(void) { return m_listTags; }
  147.  
  148.     //@cmember Walks the tag list and frees all field text memory.
  149.     void FreeTagText(void);
  150.  
  151.     //@cmember Compare via output-order attributes: topic name and
  152.     // sort order.
  153.  
  154.     int Compare(CTopic &t);
  155.  
  156.     //@cmember Compare via topic id (context string).
  157.  
  158.     int CompareContext(CTopic &t);
  159.  
  160. private:
  161.     CString m_sName;              //@field Name of topic                 
  162.     CString m_sCtx;               //@field Context string
  163.     CString m_sLocalDocTag;          //@field Per-topic extraction flags
  164.     
  165.     int             m_nWeight;        //@field Sorting weight (from format file)
  166.  
  167.     long             m_lOffset;
  168.  
  169.     CTagList        m_listTags;
  170.     
  171.     int             m_nDocTag;
  172.     long            m_lSrcLineNum;
  173.     int             m_nSrcFn;
  174. };
  175.  
  176.  
  177.  
  178. typedef CTypedPtrList<CObList, CTopic *> CTopicList;
  179.  
  180. class CTopicLog  : public CObject
  181. {
  182. public:
  183.       CTopicLog();
  184.     ~CTopicLog();
  185.  
  186. public:
  187.     BOOL Search(const char *szID, CTopic *&p);
  188.  
  189.     void Sort(BOOL bOutputSorted);
  190.  
  191.     CTopic *GetTopicOutputOrder(UINT i);
  192.     CTopic *GetTopicSortOrder(UINT i);
  193.  
  194.     UINT GetLogCount(void) { return m_listTopics.GetCount(); }
  195.     UINT GetRealCount(void) { return m_nTopics; }
  196.  
  197.     enum AddFlags {
  198.         AddOverwrite        = 0x01,
  199.         AddGenerateUnique    = 0x02,
  200.     };
  201.  
  202.     void Add(CTopic *pAdd, int nOptions);
  203.     POSITION GetHeadPosition( ) const { return m_listTopics.GetHeadPosition(); }
  204.     CTopic *GetNext(POSITION &pos) { return m_listTopics.GetNext( pos ); }
  205.  
  206.     int Print(const char *szFile, int  bConcat);
  207.  
  208.     int AddSrcFn(const char *szInput);
  209.     const char *GetSrcFn(int n = -1);
  210.     int GetSrcFnIndex(void) { return m_asSrcFn.GetUpperBound(); }
  211.  
  212.     int AddDocTag(const char *szTag);
  213.     const char *GetDocTag(int n = -1);
  214.     int GetDocTagIndex(void) { return m_asDocTags.GetUpperBound(); }
  215.  
  216. #ifdef _DEBUG
  217.     void Dump( CDumpContext &dc ) const;
  218. #endif
  219.  
  220. private:
  221.     CTopicList        m_listTopics;
  222.     CTopic          **m_apTopicSort;
  223.     CTopic          **m_apTopicOutput;
  224.     UINT             m_nTopics;
  225.     
  226.     CStrArray       m_asDocTags;
  227.     CStrArray       m_asSrcFn;
  228.     BOOL            m_bIsSorted;
  229. };
  230.  
  231.